<!DOCTYPE HTML>
<html>
<head>
<title>操纵杆测试脚本 - 脚本示例 | AutoHotkey</title>
<meta name="description" content="The joystick test script helps determine the button numbers and other attributes of your joystick, and may indicate if your joystick needs calibration." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>操纵杆测试脚本</h1>

<p>此脚本帮助您判断操纵杆的按钮数目和其他属性. 它还可能显示您的操纵杆是否需要校准; 即它的每个轴向的活动范围是否在百分之零到百分之百的范围内, 这是它应该处于的范围. 如果需要校准, 请使用操作系统控制面板或操纵杆的自带软件.
</p>
<p><a href="JoystickTest.ahk">下载此脚本</a> &nbsp;| &nbsp;<a href="index.htm">其他示例脚本</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">主页</a></p>

<pre class="NoIndent"><em>; July 6, 2005: Added auto-detection of joystick number.
; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of
; detecting whether the joystick is connected.  Some joysticks are
; gamepads and don't have even a single axis.</em>

<em>; If you want to unconditionally use a specific joystick number, change
; the following value from 0 to the number of the joystick (1-16).
; A value of 0 causes the joystick number to be auto-detected:</em>
JoystickNumber = 0

<em>; END OF CONFIG SECTION. Do not make changes below this point unless
; you wish to alter the basic functionality of the script.</em>

<em>; Auto-detect the joystick number if called for:</em>
if JoystickNumber &lt;= 0
{
    Loop 16  <em>; Query each joystick number to find out which ones exist.</em>
    {
        GetKeyState, JoyName, %A_Index%JoyName
        if JoyName &lt;&gt;
        {
            JoystickNumber = %A_Index%
            break
        }
    }
    if JoystickNumber &lt;= 0
    {
        MsgBox The system does not appear to have any joysticks.
        ExitApp
    }
}

#SingleInstance
SetFormat, float, 03  <em>; Omit decimal point from axis position percentages.</em>
GetKeyState, joy_buttons, %JoystickNumber%JoyButtons
GetKeyState, joy_name, %JoystickNumber%JoyName
GetKeyState, joy_info, %JoystickNumber%JoyInfo
Loop
{
    buttons_down =
    Loop, %joy_buttons%
    {
        GetKeyState, joy%A_Index%, %JoystickNumber%joy%A_Index%
        if joy%A_Index% = D
            buttons_down = %buttons_down%%A_Space%%A_Index%
    }
    GetKeyState, JoyX, %JoystickNumber%JoyX
    axis_info = X%JoyX%
    GetKeyState, JoyY, %JoystickNumber%JoyY
    axis_info = %axis_info%%A_Space%%A_Space%Y%JoyY%
    IfInString, joy_info, Z
    {
        GetKeyState, JoyZ, %JoystickNumber%JoyZ
        axis_info = %axis_info%%A_Space%%A_Space%Z%JoyZ%
    }
    IfInString, joy_info, R
    {
        GetKeyState, JoyR, %JoystickNumber%JoyR
        axis_info = %axis_info%%A_Space%%A_Space%R%JoyR%
    }
    IfInString, joy_info, U
    {
        GetKeyState, JoyU, %JoystickNumber%JoyU
        axis_info = %axis_info%%A_Space%%A_Space%U%JoyU%
    }
    IfInString, joy_info, V
    {
        GetKeyState, JoyV, %JoystickNumber%JoyV
        axis_info = %axis_info%%A_Space%%A_Space%V%JoyV%
    }
    IfInString, joy_info, P
    {
        GetKeyState, JoyP, %JoystickNumber%JoyPOV
        axis_info = %axis_info%%A_Space%%A_Space%POV%JoyP%
    }
    ToolTip, %joy_name% (#%JoystickNumber%):`n%axis_info%`nButtons Down: %buttons_down%`n`n(right-click the tray icon to exit)
    Sleep, 100
}
return
</pre>
</body>
</html>
